package singleton.lazy;

/**
 * 双重检查配合volatile
 * volatile保证写的原子性，禁止写操作和写之前的任何读写重排序
 */
public class Singleton8 {
    private Singleton8(){}
    private static volatile Singleton8 instance;

    public static Singleton8 getInstance() {
        if(null == instance){
            synchronized (Singleton8.class) { //1
                if(null == instance) { //2
                    instance = new Singleton8(); //3
                }
            }
        }
        return instance;
    }
}
